# 最长连续序列

class Solution(object):
    def longestConsecutive(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        result = 0
        nums_set = set(nums)

        for num in nums_set:
            if num - 1 not in nums_set:
                current_num = num
                current_length = 1
                while current_num + 1 in nums_set:
                    current_num += 1
                    current_length += 1
                result = max(result,current_length)
        return result
